home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / 80x0393.zip / CHILD.ASM < prev    next >
Assembly Source File  |  1993-06-20  |  3KB  |  91 lines

  1. ;
  2. ;  CHILD.ASM
  3. ;
  4. ;  Author:  Dave Walker
  5. ;  Placed in the public domain
  6. ;
  7.  
  8.             IDEAL
  9.             MODEL   SMALL
  10.             STACK   100h
  11.  
  12.             DATASEG
  13. keep_ss     dw      ?                   ;For saving our stack
  14. keep_sp     dw      ?
  15. PSPseg      dw      ?
  16. childspec   db      'd:\subdir\child.exe',0
  17. parmblk     dw      0                   ;Use our environment
  18.             dd      0                   ;Command tail
  19.             dd      0                   ;Pointer to first FCB
  20.             dd      0                   ;Pointer to second FCB
  21.  
  22.             CODESEG
  23. start:      mov     ax,@data            ;Setup DS
  24.             mov     ds,ax
  25.             mov     [PSPseg],es         ;Save PSP segment for later use
  26.  
  27. ;*** Reallocate memory
  28.             mov     bx,zseg             ;Our size is calculated by
  29.             mov     ax,es               ;  subtracting the address
  30.             sub     bx,ax               ;  of a "end marker" segment
  31.             mov     ah,4ah              ;  from our PSP segment.
  32.             int     21h
  33.  
  34. ;[...go on about our business for a while...]
  35.  
  36. ;*** Setup parmblk for executed program.  For simplicity, we are using
  37. ;***   the parent's environment block and PSP.
  38.  
  39. ;*** The parameter block contains four items:
  40. ;***   +00  WORD   Segment of child process' environment block (this
  41. ;***                 will normally be the same as the parent's)
  42. ;***   +02  DWORD  Address of command tail for child process (seg:ofs)
  43. ;***   +06  DWORD  Address of first FCB (normally PSP:005Ch)
  44. ;***   +0A  DWORD  Address of second FCB (normally PSP:006Ch)
  45.  
  46.             mov     es,[PSPseg]         ;ES = Our PSP seg.
  47.             mov     ax,[es:002ch]       ;AX = [PSP:002Ch] = Our
  48.             mov     [WORD parmblk],ax   ;  environment seg.
  49.  
  50.             mov     ax,0080h            ;Command tail is at PSP:0080h
  51.             mov     [WORD parmblk+2],ax
  52.             mov     [WORD parmblk+4],es
  53.  
  54.             mov     ax,005ch            ;FCB1 is at PSP:005Ch
  55.             mov     [WORD parmblk+6],ax
  56.             mov     [WORD parmblk+8],es
  57.  
  58.             mov     ax,006ch            ;FCB2 is at PSP:006Ch
  59.             mov     [WORD parmblk+10],ax
  60.             mov     [WORD parmblk+12],es
  61.  
  62. ;*** Load and execute child process
  63.             push    ds                  ;Point ES:BX to parmblk
  64.             pop     es
  65.             mov     bx,OFFSET parmblk
  66.             mov     dx,OFFSET childspec ;Point DS:DX to ASCIIZ filespec
  67.             mov     [keep_ss],ss        ;Save our stack pointer
  68.             mov     [keep_sp],sp
  69.             mov     ax,4b00h            ;Execute child process
  70.             int     21h
  71.  
  72. ;*** After the child process returns, we can't rely on *any* registers
  73. ;*** to be intact.
  74.             mov     ax,@data            ;Reload DS
  75.             mov     ds,ax
  76.             mov     ss,[keep_ss]        ;Reload stack
  77.             mov     sp,[keep_sp]
  78.  
  79. ;*** Get return code via 21/4D (if desired)
  80.             mov     ah,4dh
  81.             int     21h
  82.  
  83. ;*** Return to DOS
  84.             mov     ax,4c00h
  85.             int     21h
  86.  
  87. SEGMENT     zseg
  88. ENDS        zseg
  89.  
  90.             END     start
  91.